//
//  DynamicVC.m
//  jinwang
//
//  Created by jzb on 2018/3/16.
//  Copyright © 2018年 jzb. All rights reserved.
//

#import "DynamicVC.h"
#import "BJDynamicSnapshotVC.h"
#import "BJDynamicLoveshotVC.h"
#import "BJDynamicGoodArticleVC.h"
#import "JWFindUserBoJianVC.h"

@interface DynamicVC ()

@property (nonatomic, strong) MLMSegmentHead *segHead;
@property (nonatomic, strong) MLMSegmentScroll *segScroll;
@property (nonatomic, strong) UIView *TabbarItemLine;
@end

@implementation DynamicVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    NSArray *list = @[@"快照",@"爱拍",@"佳文"];
//    _segHead = [[MLMSegmentHead alloc] initWithFrame:CGRM(0, 0, 750, 88) titles:list headStyle:SegmentHeadStyleLine layoutStyle:MLMSegmentLayoutDefault];
    _segHead = [[MLMSegmentHead alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 44) titles:list headStyle:SegmentHeadStyleLine layoutStyle:MLMSegmentLayoutDefault];
    //    _segHead.fontScale = 1.1;
    _segHead.fontSize = 16;
    _segHead.deSelectColor = kRGBColor(80, 80, 80);
    _segHead.selectColor = UIColorHex(0xEEA72B);
    _segHead.lineScale = .4;
    _segHead.bottomLineHeight = .5;
    _segHead.lineColor = UIColorHex(0xEEA72B);
//    _segHead.headColor = [UIColor clearColor];
    _segHead.bottomLineColor = kRGBColor(230, 230, 230);
    
    _segScroll = [[MLMSegmentScroll alloc] initWithFrame:CGRectMake(0, 44, kScreenWidth, kScreenHeight - 44-64-50)  vcOrViews:[self vcArr:list.count]];
    
    _segScroll.loadAll = YES;
    _segScroll.showIndex = 0;
    
//    _segScroll.backgroundColor = [UIColor purpleColor];
    
    [MLMSegmentManager associateHead:_segHead withScroll:_segScroll completion:^{
        
        [self.view addSubview:_segHead];
        [self.view addSubview:_segScroll];
    }];

    [self DynamicTabbarBuild];
}

- (void)DynamicTabbarBuild{
    
    NSArray *BtnTitleArr = @[@"行人",@"粉丝",@"关注",@"朋友",@"游客",@"我"];
    
    UIView *TabbarView = [[UIView alloc]initWithFrame:CGRectMake(0, kScreenHeight - 50 - 64, kScreenWidth, 50)];
    TabbarView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:TabbarView];
    UIView *TabbarViewLine = [[UIView alloc]initWithFrame:CGRM(0, 0, 750, 1)];
    TabbarViewLine.backgroundColor = [UIColor lightGrayColor];
     [TabbarView addSubview:TabbarViewLine];
    for (int i = 0; i < BtnTitleArr.count; i++) {
        UIButton *TabbarItem = [[UIButton alloc]initWithFrame:CGRectMake(kScreenWidth/6*i, 1, kScreenWidth/6, 47.5)];
//        TabbarItem.backgroundColor = [UIColor purpleColor];
        [TabbarItem setTitle:BtnTitleArr[i] forState:UIControlStateNormal];
        [TabbarItem setTitleColor:kRGBColor(80, 80, 80) forState:UIControlStateNormal];
        [TabbarItem addTarget:self action:@selector(TabbarItemOnclick:) forControlEvents:UIControlEventTouchUpInside];
        TabbarItem.tag = 1010 + i;
        if (i == 0) {
            [TabbarItem setTitleColor:UIColorHex(0xEEA72B) forState:UIControlStateNormal];
        }
        [TabbarView addSubview:TabbarItem];
    }
    _TabbarItemLine = [[UIView alloc]initWithFrame:CGRectMake(10, 48, kScreenWidth/6-20, 2)];
    _TabbarItemLine.backgroundColor = UIColorHex(0xEEA72B);
    [TabbarView addSubview:_TabbarItemLine];
    
}
- (void)TabbarItemOnclick:(UIButton *)sender{
    
    BOOL isLogin = [[ToolManager sharedManager] checkLoginStateAtVC:self];
    
    if (isLogin) {
        if (sender.tag == 1015) {
            
            JWFindUserBoJianVC *vc = [JWFindUserBoJianVC new];
            vc.title = @"我的博见";
            [self.navigationController pushViewController:vc animated:YES];
            
        }else{
            UIButton *button01 = (UIButton *)[self.view viewWithTag:1010];
            UIButton *button02 = (UIButton *)[self.view viewWithTag:1011];
            UIButton *button03 = (UIButton *)[self.view viewWithTag:1012];
            UIButton *button04 = (UIButton *)[self.view viewWithTag:1013];
            UIButton *button05 = (UIButton *)[self.view viewWithTag:1014];
            UIButton *button06 = (UIButton *)[self.view viewWithTag:1015];
            
            [button01 setTitleColor:kRGBColor(80, 80, 80) forState:UIControlStateNormal];
            [button02 setTitleColor:kRGBColor(80, 80, 80) forState:UIControlStateNormal];
            [button03 setTitleColor:kRGBColor(80, 80, 80) forState:UIControlStateNormal];
            [button04 setTitleColor:kRGBColor(80, 80, 80) forState:UIControlStateNormal];
            [button05 setTitleColor:kRGBColor(80, 80, 80) forState:UIControlStateNormal];
            [button06 setTitleColor:kRGBColor(80, 80, 80) forState:UIControlStateNormal];
            [sender setTitleColor:UIColorHex(0xEEA72B) forState:UIControlStateNormal];
            _TabbarItemLine.frame = CGRectMake(10+(kScreenWidth/6)*(sender.tag-1010), 48, kScreenWidth/6-20, 2);
            NSMutableDictionary *dict =[[NSMutableDictionary alloc] init];
            [dict setValue:[NSString stringWithFormat:@"%ld",sender.tag - 1010] forKey:@"post_cate"];
            
            NSNotification *notification =[NSNotification notificationWithName:@"JWBJDynamicNotification" object:nil userInfo:dict];
            
            [[NSNotificationCenter defaultCenter] postNotification:notification];
        }
        
    }
}
#pragma mark - 数据源
- (NSArray *)vcArr:(NSInteger)count {
    NSMutableArray *arr = [NSMutableArray array];
    
    BJDynamicSnapshotVC *Snapshot_VC = [[BJDynamicSnapshotVC alloc]init];
    BJDynamicLoveshotVC *Loveshot_VC = [[BJDynamicLoveshotVC alloc]init];
    BJDynamicGoodArticleVC *GoodArticle_VC = [[BJDynamicGoodArticleVC alloc]init];
    
    Snapshot_VC.VCType = 0;
    Loveshot_VC.VCType = 0;
    GoodArticle_VC.VCType = 0;
    
    [arr addObject:Snapshot_VC];
    [arr addObject:Loveshot_VC];
    [arr addObject:GoodArticle_VC];
    
    return arr;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
